
#include "stdafx.h"
#include "ConstDef.h"
#include "ReloadCode.h"
#include "ReloadApp.h"
#include "ReloadPacket.h"
#include "ReloadDebugPacket.h"

namespace reload
{
	NodeInfo::NodeInfo()
	{

	}

	NodeInfo::~NodeInfo()
	{

	}

	retT NodeInfo::readFromBuffer( boost::shared_ptr<asyframe::IoBuffer> _pBuffer )
	{
		READFROMBUFFER_START;
		R(nodeId_.readFromBuffer(_pBuffer));
		R(ipAddressPort_.readFromBuffer(_pBuffer));
		READFROMBUFFER_END;
	}

	retT NodeInfo::writeToBuffer( boost::shared_ptr<asyframe::IoBuffer> _pBuffer )
	{
		WRITETOBUFFER_START;
		R(nodeId_.writeToBuffer(_pBuffer));
		R(ipAddressPort_.writeToBuffer(_pBuffer));
		WRITETOBUFFER_END;
	}

	std::size_t NodeInfo::size()
	{
		return nodeId_.size() + ipAddressPort_.size();
	}

	////////////////////////////////////////////////////////////////////////////////////////////

	ChordInfoDebugPacket::ChordInfoDebugPacket()
	{

	}

	ChordInfoDebugPacket::~ChordInfoDebugPacket()
	{

	}

	retT ChordInfoDebugPacket::readFromBuffer( boost::shared_ptr<asyframe::IoBuffer> _pBuffer )
	{
		READFROMBUFFER_START;
		R(selfNodeInfo_.readFromBuffer(_pBuffer));
		R(predecessors_.readFromBuffer(_pBuffer));
		R(successors_.readFromBuffer(_pBuffer));
		R(fingers_.readFromBuffer(_pBuffer));
		READFROMBUFFER_END;
	}

	retT ChordInfoDebugPacket::writeToBuffer( boost::shared_ptr<asyframe::IoBuffer> _pBuffer )
	{
		WRITETOBUFFER_START;
		R(selfNodeInfo_.writeToBuffer(_pBuffer));
		R(predecessors_.writeToBuffer(_pBuffer));
		R(successors_.writeToBuffer(_pBuffer));
		R(fingers_.writeToBuffer(_pBuffer));
		WRITETOBUFFER_END;
	}

	std::size_t ChordInfoDebugPacket::size()
	{
		return selfNodeInfo_.size() + predecessors_.size() + successors_.size() + fingers_.size();
	}

	////////////////////////////////////////////////////////////////////////////////////////////////

	DataStorageInfoDebugPacket::DataStorageInfoDebugPacket()
		:nonReplica_(0),replica1_(0),replica2_(0),unknownReplica_(0)
	{

	}

	DataStorageInfoDebugPacket::~DataStorageInfoDebugPacket()
	{
		nonReplica_ = 0;
		replica1_ = 0;
		replica2_ = 0;
		unknownReplica_ = 0;
	}

	retT DataStorageInfoDebugPacket::readFromBuffer( boost::shared_ptr<asyframe::IoBuffer> _pBuffer )
	{
		READFROMBUFFER_START;
		R(_pBuffer->ntohRead(nonReplica_));
		R(_pBuffer->ntohRead(replica1_));
		R(_pBuffer->ntohRead(replica2_));
		R(_pBuffer->ntohRead(unknownReplica_));
		READFROMBUFFER_END;
	}

	retT DataStorageInfoDebugPacket::writeToBuffer( boost::shared_ptr<asyframe::IoBuffer> _pBuffer )
	{
		WRITETOBUFFER_START;
		R(_pBuffer->htonWrite(nonReplica_));
		R(_pBuffer->htonWrite(replica1_));
		R(_pBuffer->htonWrite(replica2_));
		R(_pBuffer->htonWrite(unknownReplica_));
		WRITETOBUFFER_END;
	}

	std::size_t DataStorageInfoDebugPacket::size()
	{
		return sizeof(nonReplica_) + sizeof(replica1_) + sizeof(replica2_) + sizeof(unknownReplica_);
	}
}
